Adding to the archive

back to section start!

 
  Well, the user has decided to Copy something to our lister or dropped 
something on us, either way we've now got the hard work of adding it to the 
archive. 
 
  1arcadd: 
  2  if checkhandler() then 
  3    return 
  4  lister set handle busy on 
  5  lister set otherhandle busy on 
  6  lister query otherhandle path 
  7  frompath = result 
  8 
  9  mustcopy = upper(right(src,length(arcsubdir))) ~== upper(arcsubdir) 
 10  if mustcopy then do 
 11    homedir = 'T:ArcDir'handle'/' 
 12    call createdirs 
 13    end 
 14  else 
 15    homedir = left(frompath,length(frompath) - length(arcsubdir)) 
 16 
 17  if mustcopy then 
 18    do i = 1 to entries 
 19      lister query otherhandle entry '"'name.i'"' stem fileinfo. 
 20      if fileinfo.type > 0 then 
 21        address command 'Copy "'frompath||name.i'" "T:ArcDir'handle'/'arcsubdir||name.i'" ALL CLONE QUIET' 
 22      else 
 23        address command 'Copy "'frompath||name.i'" "T:ArcDir'handle'/'arcsubdir'" CLONE QUIET' 
 24      end 
 25 
 26  lister set handle title getcatstr(12,'Adding to archive...') 
 27  lister refresh handle full 
 28 
 29  select 
 30    when arctype = 'LHA' then do 
 31      call open('actionfile','T:actionfile'handle,'w') 
 32      call writeln('actionfile','"'patch(homedir,0)'"') 
 33      do i = 1 to entries 
 34        call writeln('actionfile','"'patch(arcsubdir||name.i,0)'"') 
 35        end 
 36      call close('actionfile') 
 37 
 38      if pos('.LZH/',test) > 0 then 
 39        method = '-0' 
 40      else 
 41        method = '' 
 42      address command 'LhA r' method '-q -e -r -X -Qo "'patch(arcfile,0)'" @T:actionfile'handle 
 43      problem = rc > 0 
 44      call delete('T:actionfile'handle) 
 45      end 
 46    when arctype = 'LZX' then do 
 47      lzxcmd = 'LZX u -q -a -e -r -X0 --' lzxkludge(patch(arcfile,0)) 
 48      linelen = 0 
 49      n = 0 
 50      do i = 1 to entries 
 51        dothis = lzxkludge(patch(arcsubdir||name.i,0)) 
 52        linelen = linelen + length(dothis) + 1 
 53        if i = 1 | linelen > 255 then do 
 54          n = n + 1 
 55          dothese.n = dothis 
 56          linelen = length(lzxcmd) + length(dothis) + 1 
 57          end 
 58        else 
 59          dothese.n = dothese.n dothis 
 60        end 
 61 
 62      oldcurrent = pragma('d') 
 63      call pragma('d',homedir) 
 64      do i = 1 to n 
 65        address command lzxcmd dothese.i 
 66        problem = rc > 0 
 67        if problem then 
 68          leave 
 69        end 
 70      call pragma('d',oldcurrent) 
 71      end 
 72    end 
 73 
 74  if mustcopy then 
 75    address command 'Delete >NIL: T:ArcDir'handle 'ALL QUIET' 
 76 
 77  if problem then 
 78    call displayerror(getcatstr(13,'Error while adding to archive.')) 
 79  else do 
 80    do i = 1 to entries 
 81      lister select otherhandle '"'name.i'"' off 
 82      end 
 83    lister refresh otherhandle 
 84    call delete('T:ArcDir.list'handle) 
 85    call arclist 
 86    end 
 87 
 88  lister set otherhandle busy off 
 89  return 
 
Line: 
 1      Sub-routine label. 
 2 - 3  We call the  checkhandler  routine to make sure that the other lister 
        wasn't a custom handler, if it was we return immediately. 
 4 - 5  Turn the state of both listers to busy so the user can't play with 
        them. 
 6 - 7  We get the path of the other lister so we know where the files are 
        coming from and assign it to frompath. 
 8      This seems rather a complex way of doing things to me, but we set 
        mustcopy to true (1) if we're not in the root directory of the 
        archive. 
 9 - 12 If mustcopy is true then we set homedir to a temporary directory in 
        T:, and call the  createdirs  routine to create it. 
13 - 14 mustcopy wasn't true so we set homedir to the path in the other 
        lister. 
17 - 24 If mustcopy did get set in line 9, then we need to copy the files or 
        dirs to the directory structure created in T:.  We use 
         lister query entry  to get each entries TYPE, if it's a file, (<0), 
        we copy it straight to the directory in T:, if it's a directory, 
        (>0), we copy it's directory structure to the directory in T:. 
26 - 27 Change the lister's titlebar to show what we're doing, translating if 
        necessary through  getcatstr . 
29      Depending on what type of archive it was, LhA or LZX, the appropriate 
        block of statements in the Select...When conditional block gets 
        executed.  I'll just describe the LhA side, you can work out the 
        other :) 
31 - 32 We open a file in T: for writing to, it will contain the entries that 
        we want to add.  The first line we write is the variable homedir. 
33 - 35 A DO loop in which we write the entry to the temporary file in T:, 
         patching  the string for strange characters.  Keep doing 
        it until there are no more entries to add. 
36      Close the temporary file. 
38 - 41 If the archive ends in .LZH we set the archiver method to '-0' to 
        retain compatibility when we add the entries, (see LhA docs). 
42      Call the archiver to add the entries  patching  for any strange 
        characters in the archive name and passing the list of entries to add 
        in the temporary file. 
43      If there was a problem we set problem to 1. 
44      Delete the temporary file. 
45      End of the When block for LhA archives. 
74 - 75 If mustcopy was set, then we delete the directory structure that was 
        created in T:. 
77 - 78 There was a problem adding the files and RC got set to something 
        other than 0, so we display an error message via the  displayerror  
        routine. 
79 - 86 There wasn't a problem, so we unselect the files in the other lister 
        and refresh it's display.  We delete the archive contents list in T: 
        because it's now out of date and call  arclist  to generate a new 
        one. 
88 - 89 We set the state of the other lister to idle and return. 
 

DOpus PLUS - giving you that bit extra...